package com.monicash.monicash.login.modle

import android.util.Log
import androidx.lifecycle.MutableLiveData
import com.monicash.monicash.app.LogUtils
import com.monicash.monicash.base.BaseModle
import com.monicash.monicash.bean.WeblinkConfigBean
import com.monicash.monicash.netconfig.Apis
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody


class LoginModle : BaseModle(){

    private val  coroutineScope = CoroutineScope(Dispatchers.Default)

    companion object{
        val instant by lazy (LazyThreadSafetyMode.SYNCHRONIZED){
            LoginModle()
        }
    }

    fun getLoginMiLuPageData(country:String,mobile:String):String?{
        var result:String? = ""
        coroutineScope.launch {
            try {
                val map = HashMap<String,String>()
                map["country"] = country
                map["mobile"] = mobile
                val mapString = getMiLuPageJson(map,false)
                val request : RequestBody = RequestBody.create("application/json".toMediaTypeOrNull(), mapString)
                val data = Apis.apiLoginServer.checkMiLuPageMobileRegister(request)
                result = decryptingMiLuPageData (data)
                LogUtils.logE("e ：$result")
            }catch (e:Exception){
                LogUtils.logE("e ：$e")
            }
        }
        return result
    }
}